home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
ediff.el
< prev
next >
Wrap
Text File
|
1996-07-02
|
44KB
|
1,238 lines
;;; ediff.el --- a comprehensive visual interface to diff & patch
;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
;; Author: Michael Kifer <kifer@cs.sunysb.edu>
;; Created: February 2, 1994
;; Keywords: comparing, merging, patching, version control.
(defconst ediff-version "2.61" "The current version of Ediff")
(defconst ediff-date "June 10, 1996" "Date of last update")
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Never read that diff output again!
;; Apply patch interactively!
;; Merge with ease!
;; This package provides a convenient way of simultaneous browsing through
;; the differences between a pair (or a triple) of files or buffers. The
;; files being compared, file-A, file-B, and file-C (if applicable) are
;; shown in separate windows (side by side, one above the another, or in
;; separate frames), and the differences are highlighted as you step
;; through them. You can also copy difference regions from one buffer to
;; another (and recover old differences if you change your mind).
;; Ediff also supports merging operations on files and buffers, including
;; merging using ancestor versions. Both comparison and merging operations can
;; be performed on directories, i.e., by pairwise comparison of files in those
;; directories.
;; In addition, Ediff can apply a patch to a file and then let you step
;; though both files, the patched and the original one, simultaneously,
;; difference-by-difference. You can even apply a patch right out of a
;; mail buffer, i.e., patches received by mail don't even have to be saved.
;; Since Ediff lets you copy differences between buffers, you can, in
;; effect, apply patches selectively (i.e., you can copy a difference
;; region from file_orig to file, thereby undoing any particular patch that
;; you don't like).
;; Ediff is aware of version control, which lets the user compare
;; files with their older versions. Ediff can also work with remote and
;; compressed files. Details are given below.
;; Finally, Ediff supports directory-level comparison, merging and patching.
;; See the on-line manual for details.
;; This package builds upon the ideas borrowed from emerge.el and several
;; Ediff's functions are adaptations from emerge.el. Much of the functionality
;; Ediff provides is also influenced by emerge.el.
;; The present version of Ediff supersedes Emerge. It provides a superior user
;; interface and has numerous major features not found in Emerge. In
;; particular, it can do patching, and 2-way and 3-way file comparison,
;; merging, and directory operations.
;;; Bugs:
;; 1. The undo command doesn't restore deleted regions well. That is, if
;; you delete all characters in a difference region and then invoke
;; `undo', the reinstated text will most likely be inserted outside of
;; what Ediff thinks is the current difference region. (This problem
;; doesn't seem to exist with XEmacs.)
;;
;; If at any point you feel that difference regions are no longer correct,
;; you can hit '!' to recompute the differences.
;; 2. On a monochrome display, the repertoire of faces with which to
;; highlight fine differences is limited. By default, Ediff is using
;; underlining. However, if the region is already underlined by some other
;; overlays, there is no simple way to temporarily remove that residual
;; underlining. This problem occurs when a buffer is highlighted with
;; hilit19.el or font-lock.el packages. If this residual highlighting gets
;; in the way, you can do the following. Both font-lock.el and hilit19.el
;; provide commands for unhighlighting buffers. You can either place these
;; commands in `ediff-prepare-buffer-hook' (which will unhighlight every
;; buffer used by Ediff) or you can execute them interactively, at any time
;; and on any buffer.
;;; Acknowledgements:
;; Ediff was inspired by Dale R. Worley's <drw@math.mit.edu> emerge.el.
;; Ediff would not have been possible without the help and encouragement of
;; its many users. See Ediff on-line Info for the full list of those who
;; helped. Improved defaults in Ediff file-name reading commands.
;;; Code:
(require 'ediff-init)
;; ediff-mult is always required, because of the registry stuff
(require 'ediff-mult)
(eval-when-compile
(load "dired")
(load-file "./ediff-ptch.el")
(load-file "./ediff-vers.el")
(load "pcl-cvs" 'noerror))
(defvar ediff-use-last-dir nil
"*If t, Ediff uses previous directory as default when reading file name.")
(defvar ediff-last-dir-A nil
"Last directory used by an Ediff command for file-A.")
(defvar ediff-last-dir-B nil
"Last directory used by an Ediff command for file-B.")
(defvar ediff-last-dir-C nil
"Last directory used by an Ediff command for file-C.")
(defvar ediff-last-dir-ancestor nil
"Last directory used by an Ediff command for the ancestor file.")
;; Some defvars to reduce the number of compiler warnings
(defvar cvs-cookie-handle)
(defvar ediff-last-dir-patch)
(defvar ediff-patch-default-directory)
;; end of compiler pacifier
;; Used as a startup hook to set `_orig' patch file read-only.
(defun ediff-set-read-only-in-buf-A ()
(ediff-eval-in-buffer ediff-buffer-A
(toggle-read-only 1)))
;; Return a plausible default for ediff's first file:
;; In dired, return the file name under the point, unless it is a directory
;; If the buffer has a file name, return that file name.
(defun ediff-get-default-file-name ()
(cond ((eq major-mode 'dired-mode)
(let ((f (dired-get-filename nil 'no-error)))
(if (and (stringp f) (not (file-directory-p f)))
f)))
((buffer-file-name (current-buffer))
(file-name-nondirectory (buffer-file-name (current-buffer))))
))
;;; Compare files/buffers
;;;###autoload
(defun ediff-files (file-A file-B &optional startup-hooks)
"Run Ediff on a pair of files, FILE-A and FILE-B."
(interactive
(let ((dir-A (if ediff-use-last-dir
ediff-last-dir-A
default-directory))
dir-B f)
(list (setq f (ediff-read-file-name
"File A to compare" dir-A
(ediff-get-default-file-name)))
(ediff-read-file-name "File B to compare"
(setq dir-B
(if ediff-use-last-dir
ediff-last-dir-B
(file-name-directory f)))
(progn
(setq file-name-history
(cons (ediff-abbreviate-file-name
(expand-file-name
(file-name-nondirectory f)
dir-B))
file-name-history))
f))
)))
(ediff-files-internal file-A
(if (file-directory-p file-B)
(expand-file-name
(file-name-nondirectory file-A) file-B)
file-B)
nil ; file-C
startup-hooks
'ediff-files))
;;;###autoload
(defun ediff-files3 (file-A file-B file-C &optional startup-hooks)
"Run Ediff on three files, FILE-A, FILE-B, and FILE-C."
(interactive
(let ((dir-A (if ediff-use-last-dir
ediff-last-dir-A
default-directory))
dir-B dir-C f ff)
(list (setq f (ediff-read-file-name
"File A to compare" dir-A
(ediff-get-default-file-name)))
(setq ff (ediff-read-file-name "File B to compare"
(setq dir-B
(if ediff-use-last-dir
ediff-last-dir-B
(file-name-directory f)))
(progn
(setq file-name-history
(cons
(ediff-abbreviate-file-name